package cn.kgc.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/6/29
 * @Description:
 */
@RestController
@RequestMapping("user")
public class UserController {

    @GetMapping("getById")
    @HystrixCommand(fallbackMethod = "getByIdFallbackMethod")
    public String getById(Integer id){

        if (id<0){
            throw  new RuntimeException("参数异常");
        }

        return "userService ok "+ id;
    }

    // 快速响应方法
    public String getByIdFallbackMethod(Integer id){
        System.out.println("id = " + id);
        return "服务器繁忙，请稍后再试！！！";
    }


}
